from django.db import models
from django.utils.translation import ugettext_lazy as _

from product.models import Category, CategoryManager

class CategoryTuning(Category):

    code = models.CharField(_("Code"), max_length=50, db_index=True)
    active = models.BooleanField(_("Active"), default=True)

    objects = CategoryManager()

    def get_parent(self):
        """
        Returns 'CategoryTuning' parent instead of 'Category' object
        """
        if self.parent:
            return CategoryTuning.objects.get(id=self.parent.id)
        else:
            return None

    class Meta:
        ordering = ['site', 'parent__id', 'ordering', 'name']
        verbose_name = _("Category")
        verbose_name_plural = _("Categories")
